
import { add, getCats, goodsAdd, getGoodsList,updateGoods,updateCatInfo } from '@/services/category';
import { message } from 'antd';
import { creator } from '@/utils/creator';
const Model = {
  namespace: 'category',
  state: {
    categoryList: [],
    goodsList:[]
  },
  effects: {
    *add({ payload }, { call, put }) {
      const res = yield call(add, payload);
      console.log(res, 'res');
      if (res.httpStatus === 200) {
        message.success(res.msg);
      }
    },
    *getCats({ payload }, { call, put }) {
      const res = yield call(getCats);
      console.log(res, 'res');
      if (res.httpStatus === 200) {
        yield put(creator('save', { categoryList: res.data }));
      }
    },
    *goodsAdd({ payload }, { call, put }) {
      const res = yield call(goodsAdd, payload);
      return res;
    },
    *getGoodsList({ payload }, { call, put }) {
      const res = yield call(getGoodsList, payload);
      if (res.httpStatus === 200) {
        yield put(creator('save', { goodsList: res.data }));
      }
    },
    *updateGoods({ payload }, { call, put }) {
      const res = yield call(updateGoods, payload);
      return res;
    },
    *updateCatInfo({ payload }, { call, put }) {
      const res = yield call(updateCatInfo, payload);
      return res;
    },
    
  },
  reducers: {
    save(state, { payload }) {
      return { ...state, ...payload };
    },
  },
};
export default Model;
